// _Functions_ are central in Go. We'll learn about
// functions with a few different examples.

package main

import (
	"fmt"
	"runtime"
	"time"
)

// Here's a function that takes two `int`s and returns
// their sum as an `int`.
func plus(a int, b int) int {

	// Go requires explicit returns, i.e. it won't
	// automatically return the value of the last
	// expression.
	return a + b
}

// When you have multiple consecutive parameters of
// the same type, you may omit the type name for the
// like-typed parameters up to the final parameter that
// declares the type.
func plusPlus(a, b, c int) int {
	return a + b + c
}

// 获取正在运行的函数名
func RunFuncName() string {
	pc := make([]uintptr, 1)
	runtime.Callers(2, pc)
	f := runtime.FuncForPC(pc[0])
	return f.Name()
}

// 获取当前时间
func CurrentTime() string {
	return time.Now().Local().Format("2006-01-02 15:04:05")
}

func init() {
	fmt.Println("init method.")
}

func main() {
	time := CurrentTime()
	fmt.Println("time = ", time)

	name := RunFuncName()
	fmt.Println("name = ", name)

	// Call a function just as you'd expect, with
	// `name(args)`.
	res := plus(1, 2)
	fmt.Println("1+2 =", res)

	res = plusPlus(1, 2, 3)
	fmt.Println("1+2+3 =", res)
}
